/*
 * @lc app=leetcode.cn id=744 lang=javascript
 *
 * [744] 寻找比目标字母大的最小字母
 */

// @lc code=start
/**
 * @param {character[]} letters
 * @param {character} target
 * @return {character}
 */
var nextGreatestLetter = function (letters, target) {
    let len = letters.length
    if (target < letters[0] || target >= letters[len - 1]) return letters[0]
    let left = 0, right = len - 1
    while (left < right) {
        let mid = (left + right) >> 1
        if (target >= letters[mid]) {
            left = mid + 1
        } else {
            right = mid
        }
    }
    return letters[left]
};//这种适用于查找不到时取小的做法。（由于left最终需要输出取小右边的第一位数，所以看起来取大了）
// @lc code=end

